import Vue from 'vue';
import VueRouter from "vue-router";
import Login from "@/components/Login";
import Home from "@/components/Home";
import Staff from "@/components/systemManagement/Staff";
import Menu from "@/components/systemManagement/Menu";
import Permission from "@/components/systemManagement/Permission";
import Role from "@/components/systemManagement/Role";
import Merchant from "@/components/userManagement/Merchant";
import MerchantReview from "@/components/userManagement/MerchantReview";
import Supplier from "@/components/userManagement/Supplier";
import SupplierReview from "@/components/userManagement/SupplierReview";
import User from "@/components/userManagement/User";
import Goods from "@/components/goodsManagement/Goods";
import GoodsType from "@/components/goodsManagement/GoodsType";
import DynamicInventory from "@/components/storageManagement/DynamicInventory";
import InStorage from "@/components/storageManagement/InStorage";
import InStorageReview from "@/components/storageManagement/InStorageReview";
import OutStorage from "@/components/storageManagement/OutStorage";
import OutStorageReview from "@/components/storageManagement/OutStorageReview";
import Storage from "@/components/storageManagement/Storage";
import StorageReview from "@/components/storageManagement/StorageReview";
import AllOrders from "@/components/orderManagement/AllOrders";
import AllotGoods from "@/components/orderManagement/AllotGoods";
import PurchaseRequest from "@/components/orderManagement/PurchaseRequest";
import Purchase from "@/components/orderManagement/Purchase";
import PurchaseReview from "@/components/orderManagement/PurchaseReview";
import ReturnGoods from "@/components/orderManagement/ReturnGoods";
import MerchantSA from "@/components/settleAccountsManagement/MerchantSA";
import SAReview from "@/components/settleAccountsManagement/SAReview";
import SupplierSA from "@/components/settleAccountsManagement/SupplierSA";
import Welcome from "@/components/Welcome";
import AssignRoles from "@/components/systemManagement/AssignRoles";
import UpdateStaff from "@/components/systemManagement/UpdateStaff";
import AddStaff from "@/components/systemManagement/AddStaff";
import InStorageReviewFuhe from "@/components/storageManagement/InStorageReviewFuhe";
import InStorageView from "@/components/storageManagement/InStorageView";
import OutStorageReviewFuhe from "@/components/storageManagement/OutStorageReviewFuhe";
import OutStorageView from "@/components/storageManagement/OutStorageView";
import UpdateGoodsType from "@/components/goodsManagement/UpdateGoodsType";
import AddGoodsType from "@/components/goodsManagement/AddGoodsType";
import AddGoods from "@/components/goodsManagement/AddGoods";
import UpdateGoods from "@/components/goodsManagement/UpdateGoods";
import PurchaseCheckTag from "@/components/orderManagement/PurchaseCheckTag";
import PurchaseTake from "@/components/orderManagement/PurchaseTake";
import OutStorageMake from "@/components/orderManagement/OutStorageMake";
import AssignMenu from "@/components/systemManagement/AssignMenu";
import AssignPermission from "@/components/systemManagement/AssignPermission";
Vue.use(VueRouter)

const router = new VueRouter({
    routes: [
        // 重定向
        { path: '/', redirect: '/login' },
        // 登录组件
        { path: '/login', component: Login },
        //主页
        {
            path: "/home",
            component: Home,
            redirect: '/welcome',
            children: [
                //首页
                { path: '/welcome',component: Welcome },
                //员工列表
                {
                    path: '/staff',
                    component: Staff ,
                    children: [
                        //分配角色
                        { path: '/assignRoles', component: AssignRoles },
                        //修改用户
                        { path: '/updateStaff',component: UpdateStaff },
                        //新增用户
                        { path: '/addStaff',component: AddStaff },
                    ]
                },
                //菜单列表
                { path: '/menu',component: Menu },
                //权限列表
                { path: '/permission',component: Permission },
                //角色列表
                { path: '/role',component: Role },
                //分配菜单
                { path: '/assignMenu',component: AssignMenu },
                //分配权限
                { path: '/assignPermission',component: AssignPermission },
                //商户信息
                { path: '/merchant',component: Merchant },
                //商户审核
                { path: '/merchantReview',component: MerchantReview },
                //供应商信息
                { path: '/supplier',component: Supplier },
                //供应商审核
                { path: '/supplierReview',component: SupplierReview },
                //用户列表
                { path: '/user',component: User },
                //商品列表
                { path: '/goods',component: Goods },
                //添加商品
                { path: '/addGoods',component: AddGoods },
                //修改商品
                { path: '/updateGoods',component: UpdateGoods },
                //商品类型列表
                {
                    path: '/goodsType',
                    component: GoodsType,
                    children: [
                        //修改商品类型
                        { path:'/updateGoodsType',component: UpdateGoodsType },
                        //新增商品类型
                        { path: '/addGoodsType',component: AddGoodsType }
                    ]
                },
                //动态库存
                { path: '/dynamicInventory',component: DynamicInventory },
                //入库列表
                { path: '/inStorage',component: InStorage },
                //入库列表详情
                { path: '/InStorageView',component: InStorageView },
                //入库审核
                { path: '/inStorageReview',component: InStorageReview },
                //入库审核详情
                { path: '/InStorageReviewFuhe',component: InStorageReviewFuhe },
                //出库列表
                { path: '/outStorage',component: OutStorage },
                //出库列表详情
                { path: '/OutStorageView',component: OutStorageView },
                //出库审核
                { path: '/outStorageReview',component: OutStorageReview },
                //出库审核详情
                { path: '/OutStorageReviewFuhe',component: OutStorageReviewFuhe },
                //仓库列表
                { path: '/storage',component: Storage },
                //仓库审核
                { path: '/storageReview',component: StorageReview },
                //全部订单
                { path: '/allOrders',component: AllOrders },
                //调拨商品
                { path: '/allotGoods',component: AllotGoods },
                //生成出库单
                { path: '/outStorageMake',component: OutStorageMake},
                //采购记录
                { path: '/purchase',component: Purchase },
                //采购申请
                { path: '/purchaseRequest',component: PurchaseRequest },
                //采购审核
                { path: '/purchaseReview',component: PurchaseReview },
                //采购审核通过
                { path: '/purchaseCheckTag',component: PurchaseCheckTag },
                //采购入库
                { path: '/purchaseTake',component: PurchaseTake },
                //退货
                { path: '/returnGoods',component: ReturnGoods },
                //商户结账
                { path: '/merchantSA',component: MerchantSA },
                //结账审核
                { path: '/sAReview',component: SAReview },
                //供应商结账
                { path: '/supplierSA',component: SupplierSA },
            ]
        }
    ]
})
router.beforeEach((to,from,next) => {
    if(to.path === '/home') {
        const token=window.sessionStorage.getItem('token')
        if (!token) {
            return next('/login')
        }
    }
    next()
})

export default router